<template>
  <div style="padding: 35px 20px">
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        placeholder="手机号/账户名/邮箱"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 25px">
        <van-button
          round
          block
          type="info"
          native-type="submit"
          color="linear-gradient(to right, rgb(255, 96, 52), rgb(238, 10, 36))"
          >登录</van-button
        >
      </div>
    </van-form>
    <router-link to="/Register">手机快速注册</router-link><br />
  </div>
</template>

<script>
import service from "../../utils/service";
export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    onSubmit(values) {
      console.log("submit", values);
      service({
        url: "api/user/login",
        method: "post",
        data: {
          loginname: this.username,
          password: this.password,
        },
      }).then((res) => {
        console.log(res.data);
        if (res.data.code == 10010) {
          alert("该用户不存在");
        } else if (res.data.code == 10011) {
          alert("密码错误");
        } else {
          this.$router.push("/Home").catch((err) => {});
        }
      });
    },
  },
};
</script>

<style scoped>
van-form {
  background: #fff;
}
a {
  font-size: 14px;
  text-align: right;
}
</style>